<!DOCTYPE html>
<script src='../resources/testharness.js'></script>
<script src='../resources/testharnessreport.js'></script>
<script src='resources/shadow-dom.js'></script>
<script src='../fullscreen/trusted-click.js'></script>

<div id='host0'>
  <template data-mode='open'>
    <canvas></canvas>
  </template>
</div>

<script>
convertTemplatesToShadowRootsWithin(host0);

async_test((test) => {
    document.onfullscreenerror = test.unreached_func('onfullscreenerror is not expected.');

    // All fullscreenElement should default to null.
    assert_equals(document.fullscreenElement, null);
    assert_equals(document.webkitFullscreenElement, null);
    assert_equals(document.webkitCurrentFullScreenElement, null);
    assert_equals(host0.shadowRoot.fullscreenElement, null);

    var canvas = host0.shadowRoot.querySelector('canvas');
    trusted_request(test, canvas);

    document.onfullscreenchange = test.step_func(() => {
        // Not interested in handling before or after exitFullscreen.
        if (document.fullscreenElement === null)
            return;

        assert_equals(document.fullscreenElement, host0);
        assert_equals(document.webkitFullscreenElement, host0);
        assert_equals(document.webkitCurrentFullScreenElement, host0);

        assert_equals(host0.shadowRoot.fullscreenElement, canvas);

        document.exitFullscreen();
        test.done();
    });

}, 'Test for fullscreenElement adjustment for single shadow tree.');
</script>
